package com.heima.comment.controller;

import com.heima.comment.model.dto.CommentRepayDto;
import com.heima.comment.model.dto.CommentRepayLikeDto;
import com.heima.comment.model.dto.CommentRepayListDto;
import com.heima.comment.service.CommentService;
import com.heima.common.constants.CommentConstant;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/comment_repay")
public class CommentRepayController {

    @Resource
    private CommentService commentService;


    /**
     * 加载评论回复列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadCommentRepay(@RequestBody CommentRepayListDto dto) {
        return commentService.load(dto.getCommentId(), dto.getMinDate(), dto.getSize());
    }

    /**
     * 发表评论回复
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveCommentRepay(@RequestBody CommentRepayDto dto) {
        return commentService.save(dto.getCommentId(), dto.getContent(), CommentConstant.COMMENT_TYPE_COMMENT);
    }

    /**
     * 点赞评论回复
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult saveCommentRepayLike(@RequestBody CommentRepayLikeDto dto) {
        return commentService.like(dto.getCommentId(),dto.getOperation());
    }

}